import sys
import _thread
import time

from PyQt5 import QtWidgets

from libs.ioctrl import IoCtrl
from bases import globalvar
from bases.player import SoundPlayer
from controller.main import MainWindow


# from controller.mainTest import MainWindow


# 延时线程， 所有的延时任务都放到这里，比如LED延时关闭
def delay(threadName):
    while True:
        # 以10ms作为间隔
        time.sleep(0.1)
        IoCtrl.delay()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    # 各种初始化
    IoCtrl.gpioinit()
    globalvar._init()
    SoundPlayer.init()

    mainWindow = MainWindow()
    mainWindow.showFullScreen()
    # mainWindow.showMaximized()
    # https://www.cnblogs.com/yuanjunyan/p/15044381.html

    # 创建延时线程
    try:
        _thread.start_new_thread(delay, ("Thread-delay",))
    except:
        print("Error: 无法启动线程")

    sys.exit(app.exec_())
